package main

import (
	dbinter "orm/dbinter"
	related "orm/relatable"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

func main() {
	db, err := gorm.Open("mysql", "root:123456@tcp(192.168.203.133:3306)/test?loc=Local")
	if err != nil {
		panic(err)
	}

	// fmt.Print("成功\n")
	// fmt.Print("hello world")

	defer db.Close()

	// db.CreateTable(&User{})

	//删除表
	// db.DropTable("users")

	// b := db.HasTable("user")
	// if b {
	// 	fmt.Printf("表存在\n")
	// }

	//修改表名
	// gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
	// 	return "sys_" + defaultTableName
	// }

	//增加数据
	// db.Create(&module.User{Name: "xiaofang", Age: 11, Addr: "hebei", Pic: "/static/img/111.jpg"})
	//查询数据
	// var userInfo module.User
	// db.First(&userInfo, db.Where("Name=?", "xiaofang"))
	// fmt.Println(userInfo)
	// db.Model(&userInfo).Update("Age", 33)
	// fmt.Println(userInfo)

	//创建表
	db.AutoMigrate(&related.User1{}, &related.GradeInfo{})
	related.CreateOneToOne(db)
	dbinter.OriSql(db)
}
